﻿using System;
using System.Collections.Generic;
using System.Text;
using WAD.WEB.AppCode;
using WAD.Model;
using WAD.DAL;

namespace WAD.WEB.Admin.Ajax
{
    /// <summary>
    /// FC_Order 的摘要说明
    /// </summary>
    public class FC_Order : AdminAjax
    {
        public override void AjaxMethodDispatch(String identity)
        {
            switch (identity)
            {
                case "getlist": this.GetList(); break;
                case "get": this.Get(); break;
            }
        }
        [QD.Web.Ajax.AjaxMethod]
        public void GetList()
        {
            int pageIndex = Parse.Int("page_index", 1);//当前页
            int userid = Parse.Int("userid", 0);
            int state = Parse.Int("state", -1);
            int platform = Parse.Int("platform", 0);
            string orderid = Parse.String("orderid", "");

            StringBuilder sb = new StringBuilder();
            sb.Append("1=1");

            if (userid > 0)
                sb.AppendFormat(" and user_id={0}", userid);
            if (state > -1)
                sb.AppendFormat(" and state={0}", state);
            if (platform > 0)
                sb.AppendFormat(" and platform={0}", platform);

            if (!string.IsNullOrEmpty(orderid))
                sb.AppendFormat(" and orderid='" + orderid + "'");

            PageData pg = DAOFCOrder.GetListPage("*", "id desc", pageIndex, 20, sb.ToString(), "fc_order");
            if (pg.itemCount == 0)
                DataEmpty();
            Success(pg);
        }

        [QD.Web.Ajax.AjaxMethod]
        public void Get()
        {
            int id = Parse.Int("id", 0);
            if (id < 1)
                ParamError();
            Success(DAOFCOrder.GetLeftJoin("fc_order", "fc_article", "fc_order.article_id=fc_article.id", "fc_order.id=" + id, "fc_order.*,title,url"));
        }
    }
}